//
//  UserMainViewController.m
//  StraightTrain
//
//  Created by mk on 15/11/23.
//  Copyright (c) 2015年 mk. All rights reserved.
//

#import "UserMainViewController.h"
#import "LoginViewController.h"
#import "UserMessageViewController.h"//个人中心
#import "MyPatientListViewController.h"//我的患者
#import "UserBasicMessViewController.h"//用户信息
#import "MySenderBookingViewController.h"//我发送的预约
#import "MyInvitePartMainViewController.h"//我收到的要求邀请

@interface UserMainViewController ()<LoginViewControllerDelegate,UserMessageViewControllerDelegate>

@end

@implementation UserMainViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
     titleLabel.text = @"个人中心";
    SetBtnImages(btnMore, @"main_tel_icon.png", @"")
    [self setViewData];
}

-(void)setViewData
{
    if ([gProjConfig isLogin])
    {
        labMess.text = [NSString stringWithFormat:@"你好! %@",[gProjConfig.dicUserData objectForKey:USER_tel]];
    }else
    {
        labMess.text = [NSString stringWithFormat:@"你好! 请登录"];
    }
}

-(void)rightBarAction:(id)sender
{
    AlertDelegate(alerTitle, @"拨打名医主刀客服电话:4001197900", @"取消", @"拨打")

}

#pragma mark 个人信息
-(IBAction)btnUserMessage:(id)sender
{
    if(![gProjConfig isLogin])
    {
     [self btnLogin:sender];
    }
    else
    {
        UserMessageViewController * mess = [[UserMessageViewController alloc]initWithNibName:@"UserMessageViewController" bundle:nil];
        mess.delegate = self;
        [self.navigationController pushViewController:mess animated:YES];
        
    }

}


-(IBAction)btnLogin:(id)sender
{
    if(![gProjConfig isLogin])
    {
       LoginViewController * login = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
       login.detegate = self;
       MyNavigationController *navi  = [[MyNavigationController alloc]initWithRootViewController:login];
       [self presentViewController:navi animated:YES completion:^{}];
    }
    else
    {
        UserMessageViewController * mess = [[UserMessageViewController alloc]initWithNibName:@"UserMessageViewController" bundle:nil];
        mess.delegate = self;
        [self.navigationController pushViewController:mess animated:YES];

    }
}

#pragma mark 我的患者
-(IBAction)btnMyPatient:(id)sender
{
    
    if ((NullObjToString(gProjConfig.dicUserData[USER_token])).length == 0)
    {
        UIAlertView *alertNeedLogin = [[UIAlertView alloc] initWithTitle:alerTitle message:@"请先登录!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"登录",nil];
        alertNeedLogin.tag = 100;
        [alertNeedLogin show];
     
    }else
    {
        MyPatientListViewController * patient = [[MyPatientListViewController alloc]initWithNibName:@"MyPatientListViewController" bundle:nil];
        [self.navigationController pushViewController:patient animated:YES];
    }
}


#pragma mark 我的个人中心
-(IBAction)Myaccount:(id)sender
{
    if ((NullObjToString(gProjConfig.dicUserData[USER_token])).length == 0)
    {
        UIAlertView *alertNeedLogin = [[UIAlertView alloc] initWithTitle:alerTitle message:@"请先登录!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"登录",nil];
        alertNeedLogin.tag = 100;
        [alertNeedLogin show];
        
    }else
    {
        //gerenxinxi
        UserMessageViewController * mess = [[UserMessageViewController alloc]initWithNibName:@"UserMessageViewController" bundle:nil];
        mess.delegate = self;
        [self.navigationController pushViewController:mess animated:YES];
    }
}


#pragma mark 发出的预约
-(IBAction)MakeAppointment:(id)sender
{
    if ((NullObjToString(gProjConfig.dicUserData[USER_token])).length == 0)
    {
        UIAlertView *alertNeedLogin = [[UIAlertView alloc] initWithTitle:alerTitle message:@"请先登录!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"登录",nil];
        alertNeedLogin.tag = 100;
        [alertNeedLogin show];
        
    }else
    {
        MySenderBookingViewController * sender = [[MySenderBookingViewController alloc]initWithNibName:@"MySenderBookingViewController" bundle:nil];
        [self.navigationController pushViewController:sender animated:YES];
    }
}


#pragma mark 收到的邀请
-(IBAction)ReceiveInvitation:(id)sender
{
    if ((NullObjToString(gProjConfig.dicUserData[USER_token])).length == 0)
    {
        UIAlertView *alertNeedLogin = [[UIAlertView alloc] initWithTitle:alerTitle message:@"请先登录!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"登录",nil];
        alertNeedLogin.tag = 100;
        [alertNeedLogin show];     
        
    }else
    {
        MyInvitePartMainViewController * Invite = [[MyInvitePartMainViewController alloc]initWithNibName:@"MyInvitePartMainViewController" bundle:nil];
        [self.navigationController pushViewController:Invite animated:YES];
    }
}


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 100)
    {
        if (alertView.cancelButtonIndex != buttonIndex)
        {
            LoginViewController * login = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
            login.detegate = self;
            MyNavigationController *navi  = [[MyNavigationController alloc]initWithRootViewController:login];
            [self presentViewController:navi animated:YES completion:^{}];
        }
    }else
    {
        if (alertView.cancelButtonIndex != buttonIndex)
        {
            NSString * tel = [NSString stringWithFormat:@"tel://4001197900"];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
        }
    }
}

-(void)loginSuccess
{
    [self setViewData];
    
    //填写资料
//    if (![[gProjConfig.dicUserData objectForKey:USER_isProfile] boolValue])
//    {
//        UserBasicMessViewController * base = [[UserBasicMessViewController alloc]initWithNibName:@"UserBasicMessViewController" bundle:nil];
//        [self.navigationController pushViewController:base animated:NO];
//  
//    }
}

-(void)exitLogin
{
    [self setViewData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end











